package zjh_20230328;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class Demo03 {
    public static void main(String[] args) throws IntrospectionException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchMethodException {
        //内省机制
        PropertyDescriptor propertyDescriptor = new PropertyDescriptor("name", Category.class);
        Method writeMethod = propertyDescriptor.getWriteMethod();
        Method readMethod = propertyDescriptor.getReadMethod();

        Class<Category> categoryClass = Category.class;
        Constructor<Category> constructor = categoryClass.getConstructor();
        Category category = constructor.newInstance();


        Object test = writeMethod.invoke(category, "TEST");
        System.out.println(test);
        Object invoke = readMethod.invoke(category);
        System.out.println(invoke);
        System.out.println(category);
    }

}
